Correctly implement zero byte write after packet that's a multiple of
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 23 Jul 2006 19:45:12 +0000 (19:45 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 23 Jul 2006 19:45:12 +0000 (19:45 +0000)
frame size.

git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@2257 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/jeeps/gpslibusb.c
gpsbabel/jeeps/gpsusbcommon.c
gpsbabel/jeeps/gpsusbcommon.h
gpsbabel/jeeps/gpsusbwin.c

index dcaa8bd63510aace722b324d28ecdbb8c3dd05a0..722635f21c89b50c9ad55fbbd4aebda3d5f7204e 100644 (file)
@@ -54,6 +54,7 @@ typedef struct {
 static int gusb_intr_in_ep;
 static int gusb_bulk_out_ep;
 static int gusb_bulk_in_ep;
+static gusb_llops_t libusb_llops;
 
 static usb_dev_handle *udev;
 static void garmin_usb_scan(libusb_unit_data *, int);
@@ -71,6 +72,7 @@ gusb_libusb_send(const garmin_usb_packet *opkt, size_t sz)
                                usb_strerror());
                }
        }
+
        return r;
 }
 
@@ -214,10 +216,12 @@ garmin_usb_start(struct usb_device *dev)
                fatal("Claim interfaced failed: %s\n", usb_strerror());
        }
 
+       libusb_llops.max_tx_size = dev->descriptor.bMaxPacketSize0;
 
        for (i = 0; i < dev->config->interface->altsetting->bNumEndpoints; i++) {
                struct usb_endpoint_descriptor * ep;
                ep = &dev->config->interface->altsetting->endpoint[i];
+
                switch (ep->bmAttributes & USB_ENDPOINT_TYPE_MASK) {
 #define EA(x) x & USB_ENDPOINT_ADDRESS_MASK
                        case USB_ENDPOINT_TYPE_BULK:
index a75e90f1b3a07a41c02a07aa6544c8c532f75514..35ac8d684bb26fa61d4fb9377e438da49d2d922b 100644 (file)
@@ -170,6 +170,18 @@ gusb_cmd_send(const garmin_usb_packet *opkt, size_t sz)
 
                GPS_Diag("(%-8s%s)\n", m1, m2 ? m2 : "");
         }
+       /*
+        * Recursion, when used in a disciplined way, can be our friend.
+        * 
+        * The Garmin protocol requires that packets that are exactly
+        * a multiple of the max tx size be followed by a zero length
+        * packet.  Do that here so we can see it in debugging traces.
+        */
+
+       if (sz && !(sz % gusb_llops->max_tx_size)) {
+               gusb_cmd_send(opkt, 0);
+       }
+
        return (rv);
 }
 
index 677e75789d577bb50df6bc211cf1b2dc5be7b4ad..b0865f5f06ef7c7fad192c25db50713b73ef2162 100644 (file)
@@ -32,6 +32,7 @@ typedef struct gusb_llops {
        gusb_llop_get  llop_get_bulk;
        gusb_llop_send llop_send;
        gusb_llop_close llop_close;
+       int max_tx_size;
 } gusb_llops_t;
 
 /* Provided by the common code. */
index 8e003ea444c4940e7865838c012290620caa7f51..d823738f06a9b748ec4e8f58a0fef0210eae685e 100644 (file)
@@ -72,7 +72,6 @@ gusb_win_get(garmin_usb_packet *ibuf, size_t sz)
        DWORD rxed = GARMIN_USB_INTERRUPT_DATA_SIZE;
        unsigned char *buf = (unsigned char *) &ibuf->dbuf;
        int tsz=0;
-       unsigned char *obuf = buf;
 
        while (sz) {
                /* The driver wrongly (IMO) rejects reads smaller than 
@@ -118,13 +117,7 @@ gusb_win_send(const garmin_usb_packet *opkt, size_t sz)
        WriteFile(usb_handle, obuf, sz, &rsz, NULL);
 
        if (rsz != sz) {
-               fatal ("Error sending %d bytes.   Successfully sent %d\n", sz, rsz);
-       }
-
-       if (0 == sz % usb_tx_packet_size) {
-               DWORD sz2;
-               GPS_Diag("Writing padding buffer.\n");
-               WriteFile(usb_handle, 0, 0, &sz2, NULL);
+               fatal ("Error sending %d bytes.   Successfully sent %ld\n", sz, rsz);
        }
 
        return rsz;
@@ -177,6 +170,7 @@ HANDLE * garmin_usb_start(HDEVINFO* hdevinfo, SP_DEVICE_INTERFACE_DATA *infodata
            &size, NULL)) {
                 fatal("Couldn't get USB packet size.\n");
         }
+       win_llops.max_tx_size = usb_tx_packet_size;
 
        gusb_syncup();